﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using NetDiskPRJ.DBUtility;
using System.Data.SqlClient;

namespace NetDiskPRJ.DAL
{
    /// <summary>
    /// 系统单号表 数据类
    /// </summary>
    public class SysBillList
    {
        public SysBillList()
        {
        }
        /// <summary>
        /// 获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-02-20</date> 
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FBillID,FBillName,FPrefix,FPostfix,FStartID,Fcont,FBillLen,Ffillwith,FTableName,FField,FhandInput,FModifyOperator,FpreLen ");
            strSql.Append(" FROM t_SysBillList ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-02-20</date> 
        /// </summary>
        public NetDiskPRJ.Model.SysBillList DataRowToModel(DataRow row)
        {
            NetDiskPRJ.Model.SysBillList model = new NetDiskPRJ.Model.SysBillList();
            if (row != null)
            {
                if (row["FBillID"] != null && row["FBillID"].ToString() != "")
                {
                    model.FBillID = int.Parse(row["FBillID"].ToString());
                }
                if (row["FBillName"] != null)
                {
                    model.FBillName = row["FBillName"].ToString();
                }
                if (row["FPrefix"] != null)
                {
                    model.FPrefix = row["FPrefix"].ToString();
                }
                if (row["FPostfix"] != null)
                {
                    model.FPostfix = row["FPostfix"].ToString();
                }
                if (row["FStartID"] != null && row["FStartID"].ToString() != "")
                {
                    model.FStartID = decimal.Parse(row["FStartID"].ToString());
                }
                if (row["Fcont"] != null)
                {
                    model.Fcont = row["Fcont"].ToString();
                }
                if (row["FBillLen"] != null && row["FBillLen"].ToString() != "")
                {
                    model.FBillLen = int.Parse(row["FBillLen"].ToString());
                }
                if (row["Ffillwith"] != null)
                {
                    model.Ffillwith = row["Ffillwith"].ToString();
                }
                if (row["FTableName"] != null)
                {
                    model.FTableName = row["FTableName"].ToString();
                }
                if (row["FField"] != null)
                {
                    model.FField = row["FField"].ToString();
                }
                if (row["FhandInput"] != null)
                {
                    model.FhandInput = row["FhandInput"].ToString();
                }
                if (row["FModifyOperator"] != null)
                {
                    model.FModifyOperator = row["FModifyOperator"].ToString();
                }
                if (row["FpreLen"] != null && row["FpreLen"].ToString() != "")
                {
                    model.FpreLen = int.Parse(row["FpreLen"].ToString());
                }
            }
            return model;
        }
        /// <summary>
        /// 更新系统单号表数据表,根据修改列表
        /// <creator>wangl</creator>
        /// <date>2013-02-20</date>
        /// </summary>
        /// <param name="ModelAddList"></param>
        /// <param name="ModelDeleteList"></param>
        /// <param name="ModelUpdateList"></param>
        public void UpdateByModelList(List<Model.SysBillList> ModelUpdateList)
        {
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            StringBuilder strSql = new StringBuilder();
            //更新
            foreach (Model.SysBillList sysBillModel in ModelUpdateList)
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("update t_SysBillList set ");
                strSql.Append("FPrefix=@FPrefix,");
                strSql.Append("FPostfix=@FPostfix,");
                strSql.Append("FStartID=@FStartID,");
                strSql.Append("FBillLen=@FBillLen");
                strSql.Append(" where FBillID=@FBillID");
                SqlParameter[] parameters = {
					    new SqlParameter("@FPrefix", SqlDbType.VarChar,25),
					    new SqlParameter("@FPostfix", SqlDbType.VarChar,25),
					    new SqlParameter("@FStartID", SqlDbType.Decimal,18),
					    new SqlParameter("@FBillLen", SqlDbType.Int,4),
                        new SqlParameter("@FBillID", SqlDbType.Int,4)
				};
                parameters[0].Value = sysBillModel.FPrefix;
                parameters[1].Value = sysBillModel.FPostfix;
                parameters[2].Value = sysBillModel.FStartID;
                parameters[3].Value = sysBillModel.FBillLen;
                parameters[4].Value = sysBillModel.FBillID;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters;
                cmdList.Add(cmds);
            }

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTran(cmdList);
            }
        }
    }
}
